package model;

import game_engine.GameEngine;
import game_engine.core.GameStage;
import game_engine.display.GEUtil;
import game_engine.display.Texture;

import java.awt.Color;

public class Intro implements GameStage {
	
	private boolean running = false;
	
	private Texture bomboTex;
	
	private final int introDuration = 5000;
	private final int bomboAppear = 3000;
	
	private int currentTime = 0;
	
	public Intro() {
		GameEngine ge = GameEngine.getInstance();
		Color transColor = new Color(0x00000);
		ge.addTextureToLoad("images/intro/bombo.png", transColor);
		
		while (!ge.isAllTextureLoaded()) {
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("Textures of intro are loading...");
		}
		bomboTex = GameEngine.getInstance().getTexture("images/intro/bombo.png", null);
	}

	@Override
	public void render() {
		int alpha = (int)Math.round((double)currentTime/(double)bomboAppear*255);
		if(alpha>255) alpha = 255;
		GEUtil.drawImage(bomboTex, 150, 250, 200, 80, alpha);
		if(currentTime > introDuration) stop();
	}

	@Override
	public void start() {
		running = true;
	}

	@Override
	public void stop() {
		running = false;
	}

	@Override
	public boolean isRunning() {
		return running;
	}

	@Override
	public void update(long tick) {
		if(running) currentTime+=tick;
	}

}
